#include <glib.h>

static gboolean idle_add_func(gpointer data)
{
    GMainLoop *loop = (GMainLoop *)data;
    g_return_if_fail(loop);

    g_print("%s: sleep 1s and quit \n", __FUNCTION__);
    g_usleep(1000*1000);

    g_main_loop_quit(loop);

    return TRUE;
}

gint main (gint argc, gchar **argv)
{
    GMainLoop *loop = NULL;

    loop = g_main_loop_new(NULL, TRUE);

    g_idle_add(idle_add_func, loop);

    g_main_loop_run(loop);

    g_main_loop_unref(loop);

    return 0;
}
